<%@page import="com.kensure.shike.sys.model.SKDict"%>
<%@page import="java.util.List"%>
<%@page import="com.kensure.shike.sys.service.SKDictService"%>
<%@page import="com.kensure.shike.constant.BusiConstant"%>
<%@page import="co.kensure.api.ApiUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<jsp:include page="base/header.jsp" flush="true"> 
 <jsp:param value="商品管理" name="pageTitle"/>
</jsp:include>

<!--必要样式-->
<link rel="stylesheet" href="<%=BusiConstant.context%>/common/css/style.css" type="text/css" />
<body>
<jsp:include page="base/nav.jsp" flush="true"> 
 <jsp:param value="商品管理" name="pageName"/>
</jsp:include>

<% %>

<div id="content" >
	<fieldset class="layui-elem-field">
    <div class="layui-field-box">
	    <form class="layui-form" id="chaxun">
	    	<div class="layui-form-item">
		   		<div class="layui-inline">
			    	<label class="layui-form-label">编号</label>
					<div class="layui-inline">
						<input type="text" name="id"  class="layui-input" value="">
					</div>
		    	</div>
	   		
		   		<div class="layui-inline">
			   		<label class="layui-form-label">名称</label>
					<div class="layui-inline">
						<input type="text" name="codeTitleLike" placeholder="" class="layui-input" value="">
					</div>
		    	</div>
		    
				
	        <input onclick="huodonglist(1)" class='self-btn' type="button" value="搜索">
	        
	        <input onclick="add()" class='self-btn' type="button" value="新增商品">
	         </div>
        </form>
    </div>
 	</fieldset>		
   
    <div >
        <div>	
         	<table id="headtable">
         		<thead></thead>
             	<tbody></tbody>
            </table>
        </div>
        <div id="fanye"></div>
    </div>
</div>

</body>



<script>

//JavaScript代码区域，layui初始化
layui.use(['element', 'layer', 'form', 'laydate', 'upload'], function() {
	var $ = layui.jquery;
	var element = layui.element;
	var layer = layui.layer;
	var form = layui.form;
	var laydate = layui.laydate,
		upload = layui.upload;
	
	
	var url = getbaseurl("/changshang/alllist.do");
	var data = {pageSize:100};
	postsync(url, data, function(data){
		var rows = data.resultData.rows;
		$.each(rows, function (index, item) {
			$('#sjid').append(new Option(item.name, item.id));// 下拉菜单里添加元素
		});
		layui.form.render("select");
	}, null, null);
	
});

	var table = createtable("headtable");
	
	var optfun = function(row){
		var tdinner = ""; 
		tdinner += "<button type='button' class='self-btn' onclick='add("+row.id+")'>修改</button>";
        if (row.status != 9 ) {
        	tdinner += "<button type='button' class='self-btn' onclick='shangxian("+row.id+")'>上线</button>";
        }else{
        	tdinner += "<button type='button' class='self-btn' onclick='xiaxian("+row.id+")'>下线</button>";
        }
		return tdinner;
	}

	
	var imgtdfun = function(row){
		var tdinner = "<img style='width:100px;height:100px;' src='"+row.picurl+"'>";
		return tdinner;
	}
	
	
	table.th = [{w:100,na:"编号",colname:"id"}
	,{w:200,na:"商品主图",callfun:imgtdfun}
	,{w:400,na:"商品名称",colname:"title"}
	,{w:100,na:"归结账户",colname:"changshang.name"}
	,{w:100,na:"排序",colname:"disorder"}
	,{w:100,na:"状态",colname:"statusStr"}
	,{w:200,na:"操作",callfun:optfun}];
	
	table.thinit();
	
	function sucdo(data){
		var rows = data.resultData.rows;
		fanye.init(data.resultData.total);	
		if(rows){	
			table.data = rows;
			table.tdinit();		
		}	
	}

	var fanye = new FanYe("fanye","huodonglist",0,20,1);
	
   function huodonglist(current){
	   if(!fanye.setpage(current)){
			return;
		}
	   var data = formtojson($('#chaxun'));
	   data.pageNo = fanye.current;
	   data.pageSize = fanye.limit;
	   var url = getbaseurl("/baobei/hdlist.do");
	   postdo(url, data, sucdo,null, null);
   }
   huodonglist(1);
   
   
   function doSearch(){
	   huodonglist(fanye.current);
   }
      
   function xiaxian(id){
	   if(confirm('确认下线？')){
		   var data = {id:id};
		   var url = getbaseurl('/baobei/xj.do');
		   postdo(url, data,  function(data){
			   doSearch();
		   },null, null);
	   }	
   }
   
   function shangxian(id){
	   if(confirm('确认上线？')){
		   var data = {id:id};
		   var url = getbaseurl('/baobei/sj.do');
		   postdo(url, data, function(data){
			   doSearch();
		   },null, null);
	   }	
   }
   
   function add(id){  
	   var addurl = getbaseurl('/ht/bbform');
	   if(id){
			addurl+="?id="+id; 
	   }
	   layer.open({
			type: 2,
			title: '商品修改',
			maxmin: true,
			shadeClose: false, //点击遮罩关闭层
			area : ['80%' , '80%'],
			content: addurl
	   });
   }
     
</script>


</html>